from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import permissions
from rest_framework.decorators import permission_classes
from rest_framework.filters import OrderingFilter, SearchFilter

from backend.helper import MyModelViewSet
from scratch.filters import ScratchFilter
from scratch.models import Scratch
from scratch.serializers import ScratchSerializer


@permission_classes([permissions.IsAuthenticated])
class ScratchViewSet(MyModelViewSet):
    queryset = Scratch.objects.all().order_by('-created_at')
    serializer_class = ScratchSerializer

    filter_backends = [DjangoFilterBackend, OrderingFilter, SearchFilter]
    filter_class = ScratchFilter
